#pragma once
#ifndef __G_PROFILER_H__
#define __G_PROFILER_H__

#include <string>

#include "GThread.h"
#include "GTimer.h"
#include "GPreProcessor.h"

namespace GThread
{

	class GProfileStats
	{
	public:
		const char*			Name;

		GUtil::GTimer		ReportTimer;
		
		GUInt64				HitCount;
		GUInt64				TotalTime;

							GProfileStats(const char* ProfileName, const GUtil::GTimeStamp& Stamp);
							GProfileStats();
	};

	class GProfilePoint
	{
	protected:
		const char*			Name;
		GUInt64				Start;
		GProfileStats*		Stats;

		GUInt64				UpdateStats();
		void				ReportStats(GUInt64 ElapsedTicks);

	public:
							GProfilePoint(const char* PointName, GProfileStats* Statistics);
							~GProfilePoint();
	
	};
}

#if defined G_BUILD_DEBUG

	#define G_DECLARE_PROFILER(ApiName)\
	{\
		extern G_THREAD_LOCAL GThread::GProfileStats Profiler##ApiName;\
	}
	#define G_DEFINE_PROFILER(ApiName, ReportInterval)\
	{\
		G_THREAD_LOCAL GThread::GProfileStats Profiler##ApiName(#ApiName, ReportInterval);\
	}
	#define G_PROFILE_START(ApiName, PointName)\
	{\
		GThread::GProfilePoint ProfilePoint##PointName(&Profiler##ApiName);\
	
	#define G_PROFILE_END()\
	}

#else // G_BUILD_DEBUG

	#define G_DECLARE_PROFILER(ApiName)
	#define G_DEFINE_PROFILER(ApiName)
	#define G_PROFILE_START(PointName)
	#define G_PROFILE_END()

#endif // G_BUILD_DEBUG

#endif